#!/bin/bash
# Copyright (C) Metaswitch Networks 2016
# If license terms are provided to you in a COPYING file in the root directory
# of the source code repository by which you are accessing this code, then
# the license outlined in that COPYING file applies to your use.
# Otherwise no rights are granted except for those provided to you by
# Metaswitch Networks in a separate written agreement.

set -ue

use_single_restart_queue=
local_site_name=site1
. /etc/clearwater/config

if [ $# -ne 0 ]
then
  echo "Usage: check_restart_queue_state"
  exit 1
fi

if [[ $use_single_restart_queue == "Y" ]] ; then
  /usr/share/clearwater/clearwater-queue-manager/env/bin/python /usr/share/clearwater/clearwater-queue-manager/scripts/check_queue_state.py "${management_local_ip:-$local_ip}" "$local_site_name" apply_config
else
  for apply_config_key in $( clearwater-etcdctl ls -p --recursive | grep apply_config_ | sort -n); do
    prefix="/clearwater/$local_site_name/configuration/"
    # Remove the prefix to get apply_config_<node_type> as etcd-key
    apply_config_key=${apply_config_key#$prefix}

    /usr/share/clearwater/clearwater-queue-manager/env/bin/python /usr/share/clearwater/clearwater-queue-manager/scripts/check_queue_state.py "${management_local_ip:-$local_ip}" "$local_site_name" "$apply_config_key"
  done
fi
